package com.dotflat.staffExtend.repository;

import com.dotflat.staffExtend.domain.StaffExtendInfo;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import javax.transaction.Transactional;
import java.util.List;

@Repository
public interface StaffExtendInfoRepository extends JpaRepository<StaffExtendInfo, String>, JpaSpecificationExecutor<StaffExtendInfo> {

    StaffExtendInfo findFirstByAreaIdAndStaffId(String areaId, String staffId);

    List<StaffExtendInfo> findAllByAreaIdAndStaffIdIn(String areaId, List<String> staffIds);

    @Modifying
    @Transactional // 添加事务注解
    @Query(value = "update ex_staff_extend_info set resignDate = curdate(),joinAt = null where staffId =:staffId", nativeQuery = true)
    int updateByStaffId(@Param("staffId") String staffId);


    @Modifying
    @Transactional // 添加事务注解
    @Query(value = "update ex_staff_extend_info set resignDate = null,joinAt = curdate() where staffId =:staffId", nativeQuery = true)
    int updateJoinAt(@Param("staffId") String staffId);

}
